<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link href="./css/mui.min.css" rel="stylesheet" />
<script src="./lib/jquery-2.1.4.js"></script>
<script src="/web/statics/public/js/base.js"></script>
<script src="./js/mui.min.js"></script>

<style>
</style>
</head>

<body>
	<!-- mui-pull-left -->
	<header class="mui-bar mui-bar-nav" style="background: #2f1d1a;">
		<a class="mui-action-back mui-icon mui-icon-left-nav "></a>
		<h1 class="mui-title">
			<span id="xcd" style="color: #F7F7F7;"></span>
		</h1>
	</header>
	<div class="mui-content" style="background-color: #fff">
		<!-- 			<span style="margin:10px;" id="xcd"></span>
 -->
		<!-- 巡查点：直燃机房 -->
		<form class="mui-input-group" id="fset">


			<!-- <h1>异常处理</h1> -->
		</form>

	</div>
	
	<script type="text/javascript">
		//	mui.init();
			var fileArr = [];
			var filelist;
			var value;
// 			mui.init({
// 				swipeBack: true //启用右滑关闭功能
// 			});
	function sel(){
					if (mui.os.plus) {
						var buttonTit = [{
							title: "拍照"
						}, {
							title: "从手机相册选择"
						}];


						plus.nativeUI.actionSheet({
							title: "上传图片",
							cancel: "取消",
							buttons: buttonTit
						}, function(b) { /*actionSheet 按钮点击事件*/
							switch (b.index) {
								case 0:
									break;
								case 1:
									getImage(); /*拍照*/
									break;
								case 2:
									galleryImg(); /*打开相册*/
									break;
								default:
									break;
							}
						})
					}
				};
			function initop(){
				document.getElementById('sbid').addEventListener('tap', function() {
					var f = document.getElementsByClassName("forFo");
					var forList =[];
					for(var i=0;i<f.length;i++){
						var obj ={};
						obj.itemname = f[i].firstChild.innerHTML;
						obj.itemdatatype = f[i].getAttribute("ftype");
						obj.itemunit = f[i].getAttribute("itemunit")=='无'?'':f[i].getAttribute("itemunit");
						obj.minvalue = f[i].getAttribute("minvalue");
						obj.maxvalue = f[i].getAttribute("maxvalue");
						if(f[i].getAttribute("ftype")=='Y/N'){
							var radio=document.getElementsByName("radio"+f[i].id);
							for(var j=0;j<radio.length;j++){
								if(radio[j].checked==true) {
									selectvalue=radio[j].value;
									obj.itemvalue=selectvalue;
									break;
								}	
							}
						}else{
							obj.itemvalue=document.getElementById("input"+f[i].id+"").value
						}
						forList.push(obj);
					}
					alert(filelist);
					var radioAll=document.getElementsByName("radioAll");
					var aValue;
					for(var k=0;k<radioAll.length;k++){
						if(radioAll[k].checked==true) {
							aValue=radioAll[k].value;
							break;
						}	
					}
					mui.ajax("/h5prop/insertchktask",{
									dataType:"JSON",
									type:"POST",
									data:{
										chkpointid:value,
										datarecord:JSON.stringify(forList),
										filelist:JSON.stringify(filelist),
										chkdes:document.getElementById('des').value,
										iserror:aValue
										},
									success:function(data){
										alert(data)
									}
					});
				//	alert(JSON.stringify(forList));//拼接
				});
					
				
				
				document.getElementById('uploadImage').addEventListener('click', function() {
								var files = fileArr;
								var wt = plus.nativeUI.showWaiting();
								var task = plus.uploader.createUpload('/test/uploadtest', {
										method: "POST"
									},
									function(t, status) { //上传完成
										if (status == 200) {
											alert("上传成功：" + t.responseText);
											filelist=JSON.parse(t.responseText);
											wt.close(); //关闭等待提示按钮
										} else {
											alert("上传失败：" + status);
											wt.close(); //关闭等待提示按钮
										}
									}
								);
								//将文件集合添加到上传队列中
								for (var i = 0; i < files.length; i++) {
									var f = files[i];
									task.addFile(f.src, {
										key: i
									});
								}
								//传其他的参数 如备注
								//添加其他参数
								//遍历5个input框
				
								task.addData("comment", "test");
								task.start();
							});
			}

			// 拍照获取图片  
			function getImage() {
				var c = plus.camera.getCamera();
				c.captureImage(function(e) {
					plus.io.resolveLocalFileSystemURL(e, function(entry) {
						var imgSrc = entry.toLocalURL() + "?version=" + new Date().getTime(); //拿到图片路径  
						setFile(imgSrc);
						setHtml(imgSrc);
					}, function(e) {
						console.log("读取拍照文件错误：" + e.message);
					});
				}, function(s) {
					console.log("error" + s.message);
				}, {
					filename: "_doc/camera/"
				})
			}
			// 从相册中选择图片   
			function galleryImg() {
				// 从相册中选择图片  
				plus.gallery.pick(function(e) {
					for (var i in e.files) {
						var fileSrc = e.files[i];
						setFile(fileSrc);
						setHtml(fileSrc);
					}
				}, function(e) {
					console.log("取消选择图片");
				}, {
					filter: "image",
					multiple: true,
					//maximum: 5,
					system: false,
					onmaxed: function() {
						plus.nativeUI.alert('最多只能选择5张图片');
					}
				});
			}


			function setHtml(path) {
				var str = '';
				str = '<li class="mui-table-view-cell mui-media mui-col-xs-6">' +
					'<img class="mui-media-object" src="' + path + '">' +
					'<span class="mui-icon mui-icon-trash deleteBtn"></span>' +
					//					'<div class="mui-media-body">'+
					//						'<input type="text" class="remark" placeholder="备注">'+
					//					'</div>'+
					'</li>';
				document.getElementById("imgs").innerHTML += str
				//jQuery("#imgs").append(str);
			}

			function setFile(fileSrc) {
				var image = new Image();
				image.src = fileSrc;
				fileArr.push(image);
			}


			
			$(document).ready(function(){
				var value =$.getUrlParam("id");
				$.ajax({url:"/h5prop/queryChkinputitemlistbyckpid",
								dataType:"JSON",
								type:"POST",
								data:{"chkpointid":value},
								success:function(data){
									// mui.toast(JSON.parse(data.length));
									var content="";
									var d = data;
									document.getElementById("xcd").innerHTML = d.chkinputitemlist[0].chkpointname;
									//return;
									for(var i=0;i<d.chkinputitemlist.length;i++){
										var maxvalue,minvalue;
										if(!d.chkinputitemlist[i].maxvalue){
											maxvalue="";
										}
										if(!d.chkinputitemlist[i].mixvalue){
											minvalue="";
										}
										if(d.chkinputitemlist[i].itemdatatype=='数值'){
											content+='<div class="mui-input-row forFo" maxvalue="'+maxvalue+'" minvalue="'+minvalue+'" itemunit="'+d.chkinputitemlist[i].itemunit+'" id="'+d.chkinputitemlist[i].id+'" ftype="'+d.chkinputitemlist[i].itemdatatype+'">'+
												'<label>'+d.chkinputitemlist[i].itemname+'</label>'+
												'<input type="text" id="input'+d.chkinputitemlist[i].id+'" placeholder="'+d.chkinputitemlist[i].itemname+'(单位:'+d.chkinputitemlist[i].itemunit+')">'+
												
											'</div>';
										}else if(d.chkinputitemlist[i].itemdatatype=='文本'){
											content+='<div class="mui-input-row forFo" maxvalue="'+maxvalue+'" minvalue="'+minvalue+'" itemunit="'+d.chkinputitemlist[i].itemunit+'" id="'+d.chkinputitemlist[i].id+'" ftype="'+d.chkinputitemlist[i].itemdatatype+'">'+
												'<label>'+d.chkinputitemlist[i].itemname+'</label>'+
												'<input type="text" id="input'+d.chkinputitemlist[i].id+'"  placeholder="'+d.chkinputitemlist[i].itemname+'(单位:'+d.chkinputitemlist[i].itemunit+')">'+
											'</div>';
										}else if(d.chkinputitemlist[i].itemdatatype=='Y/N'){
											content+='<div class="mui-input-row forFo" maxvalue="'+maxvalue+'" minvalue="'+minvalue+'" itemunit="'+d.chkinputitemlist[i].itemunit+'" id="'+d.chkinputitemlist[i].id+'" ftype="'+d.chkinputitemlist[i].itemdatatype+'">'+
												'<label>'+d.chkinputitemlist[i].itemname+'</label>'+
												'<div class=" mui-radio mui-pull-left mui-left">'+
													'<label>是</label>'+
													'<input name="radio'+d.chkinputitemlist[i].id+'" value="是" type="radio" checked>'+
												'</div>'+
												'<div class="mui-radio mui-pull-left mui-left">'+
													'<label>否</label>'+
													'<input name="radio'+d.chkinputitemlist[i].id+'" value="否" type="radio">'+
												'</div>'+
											'</div>';
										}
									}
									content+='<div class="mui-input-row">'+
										'<label>备注</label>'+
										'<input type="text" id="des"  placeholder="备注">'+
									'</div>';
									content+='<div class="mui-input-row">'+
									'<label>上传</label>'+
									
									
									'<a class="">'+
									'	<span id="headImage" class="mui-icon mui-icon-camera" onclick="sel()"></span>'+
									'</a>'+
									'<a class="">'+
									'	<span id="uploadImage" class="mui-icon mui-icon-upload"></span>'+
									'</a>'+
									'</div>'+
									// '<div class="mui-input-row">'+
										'<ul id="imgs" class="mui-table-view mui-grid-view">'+
										'</ul>';
									// '</div>';
									content+='<div class="mui-input-row">'+
										'<label>整体</label>'+
										'<div class=" mui-radio mui-pull-left mui-left">'+
											'<label>正常</label>'+
											'<input name="radioAll" type="radio" value="1" checked>'+
										'</div>'+
										'<div class="mui-radio mui-pull-left mui-left">'+
											'<label>异常</label>'+
											'<input name="radioAll" value="0" type="radio">'+
										'</div>'+
									'</div>'+
									'<div class="mui-button-row">'+
											'<button type="button" class="mui-btn mui-btn-blue" id="sbid" >提交</button>'+
									'</div>';
									document.getElementById("fset").innerHTML=content;
									initop();
								},
								error:function(e,type){
								//	mui.toast(type);
								}
				});
			});
		</script>
</body>

</html>
